package tools 
{
	import Entities.Note;
	import flash.display.Graphics;
	import flash.geom.Point;
	import screens.NoteCanvas;
	import flash.events.MouseEvent;
	import Buttons.Tool;
	/**
	 * ...
	 * @author Andy Wolff
	 */
	public class CopyNotesTool implements INoteTool
	{
		private var view:NoteCanvas;
		private var note:Note;
		private var previousPoint:Point;
		public function CopyNotesTool(view:NoteCanvas) 
		{
			this.view = view;
		}
		
		public function mouseDown(e:MouseEvent):void {
			//get the note you clicked on and copy it
			end();
			previousPoint = new Point(e.localX, e.localY);
			view.saveState();
			note = view.getCurrentInstrument().getNoteAtPosition(previousPoint); //get
			previousPoint = new Point(e.localX+view.getViewPos(), e.localY);
			if (note != null && view.whichTool() == Tool.COPY) {
				note = new Note(view.getCurrentInstrument(), note.getWhich(), note.getStart(), note.getEnd()); //copy the note
				view.getCurrentInstrument().addNote(note);
			}
		}
		
		public function mouseMove(e:MouseEvent):void {
			//move the note around
			if (note != null && previousPoint != null) {
				note.move(NoteCanvas.getNoteRow(e.localY), (e.localX+view.getViewPos() - previousPoint.x));
				previousPoint= new Point(e.localX+view.getViewPos(), e.localY);
			}
			
		}
		
		public function mouseUp(e:MouseEvent):void {
			//drop the note into the instrument
			end();
		}
		
		public function end():void {
			view.getCurrentInstrument().unify();
			note = null;
			previousPoint = null;
		}
		
		public function draw(g:Graphics):void {
			if (note!=null) note.draw(g, view.getPlayArea());
		}
		
	}

}